//
//  MyJobCollectionController.m
//  Job
//
//  Created by 如此的你 on 2018/8/23.
//  Copyright © 2018年 桑赐相. All rights reserved.
//

#import "MyJobCollectionController.h"
#import "JobTableViewCell.h"
#import "JoBDetailsViewController.h"

@interface MyJobCollectionController ()

@end

@implementation MyJobCollectionController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的收藏";
    [self.tableView registerNib:[UINib nibWithNibName:@"JobTableViewCell" bundle:nil] forCellReuseIdentifier:@"JobTableViewCell"];
    [self.tableView.mj_header beginRefreshing];
}

-(void)down_refreshData{
    self.page = 1;
    [self getData:YES];
}

-(void)loadMoreData{
    self.page ++;
    [self getData:NO];
}

- (void)getData:(Boolean)isRefresh{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"page"] = @(self.page);
    
    [HTTPTools GET:getCollectionUrl parameters:dict callback:^(id result, NSString *msg, NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        if (!error) {
            if (!msg) {
                NSArray *array = [JobModel mj_objectArrayWithKeyValuesArray:result];
                if (isRefresh) {
                    [self.dataSource removeAllObjects];
                }
                [self.dataSource addObjectsFromArray:array];
                
//                if (array.count < 20) {
//                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
//                }else{
//                    [self.tableView.mj_footer resetNoMoreData];
//                }
                [self reloadData];
            }
        }
    }];
}
#pragma mark - UITableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    JobTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JobTableViewCell" forIndexPath:indexPath];
    
    XLJobModel *model = self.dataSource[indexPath.row];
    [cell setModel:model withHideIcon:NO];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 105.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    JoBDetailsViewController *detail = [JoBDetailsViewController new];
    detail.model = self.dataSource[indexPath.row];
    [self pushViewController:detail];
}













@end
